home *** CD-ROM | disk | FTP | other *** search
- // The script converts a .tex file to DVI format using MiKTeX,
- // then it takes the DVI file and converts to PostScript using
- // GhostScript. All the conversions runs in command line mode.
- // After that the script starts GSView to display the document.
- // In each stage it catches errors and reports them in pop-up
- // message boxes.
- //
- // Autor: Korolev Sergey (sergey_korolev@inbox.ru)
- // Version: 1.0
-
- var ICONERROR = 0x10;
- var LATEX_CMD = "latex ";
- var DVIPS_CMD = "dvips ";
- var DVI_EXT = ".dvi";
- var PS_EXT = ".ps";
-
- if (Application.FileName() == "") {
- Application.Message("Error",
- "Please specify a filename first (save current file).",
- ICONERROR);
- } else {
- var Name = "";
- var Ext = "";
- var FullName = Application.FileName();
- var ExtOffset = FullName.lastIndexOf('.');
-
- if (ExtOffset == -1) {
- ExtOffset = FullName.length;
- }
-
- Name = FullName.substring(
- FullName.lastIndexOf('\\') + 1, ExtOffset);
-
- if (ExtOffset + 1 < FullName.length) {
- Ext = FullName.substring(ExtOffset + 1);
- }
-
- Console.SetVisible(true);
-
- if (Shell.FileExist(Name + DVI_EXT)) {
- Shell.DeleteFile(Name + DVI_EXT);
- }
-
- Console.Execute(LATEX_CMD + Name + '.' + Ext);
-
- if (Shell.FileExist(Name + DVI_EXT)) {
- if (Shell.FileExist(Name + PS_EXT)) {
- Shell.DeleteFile(Name + PS_EXT);
- }
-
- Console.Execute(DVIPS_CMD + Name + DVI_EXT);
-
- if (Shell.FileExist(Name + PS_EXT)) {
- Shell.Execute("open", Name + PS_EXT,"","",1);
- } else {
- Application.Message("Error",
- "Can't convert " + DVI_EXT + " file to "
- + PS_EXT + " file.", ICONERROR);
- }
- } else {
- Application.Message("Error",
- "There is an error in Latex source file.",
- ICONERROR);
- }
- }